package com.kawaiior.asoulworld.item.weapon;

import com.kawaiior.asoulworld.item.ItemASWeapon;
import com.kawaiior.asoulworld.util.EntityUtil;
import com.kawaiior.asoulworld.util.IDLGeneral;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.List;

public class ItemEileenRosemary extends ItemASWeapon {
    public ItemEileenRosemary(String name, ToolMaterial material) {
        super(name, material);
        useable = true;
        base_cd = 15f;
        base_range = 8f;
        attackDamage = 4f;
    }

    @Override
    public int getMaxDamage(ItemStack stack) {
        return 128;
    }

    @Override
    public EnumAction getItemUseAction(ItemStack stack)
    {
        return EnumAction.BLOCK;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 20;
    }

    public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
    {
        //IdlFramework.Log("onCreatureStoppedUsing");
        Vec3d basePos = entityLiving.getPositionVector();
        float range = getRange(stack);
        List<EntityLivingBase> entities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, IDLGeneral.ServerAABB(basePos.addVector(-range, -range, -range), basePos.addVector(range, range, range)));
        //IdlFramework.Log("found %d targets", entities.size());
        for (EntityLivingBase target: entities) {
            if (EntityUtil.getAttitude(entityLiving, target) != EntityUtil.ATTITUDE.FRIEND)
            {
                if (worldIn.isRemote)
                {
                    EntityUtil.SpawnParticleAround(target, EnumParticleTypes.WATER_SPLASH, 10);
                }else {
                    EntityUtil.ApplyBuff(entityLiving, MobEffects.BLINDNESS,0,5f);
                    EntityUtil.ApplyBuff(target,MobEffects.WITHER,1,19f);
                    stack.damageItem(2, entityLiving);
                }
            }
        }
        entityLiving.playSound(SoundEvents.ENTITY_SPLASH_POTION_BREAK, 1f, 0.8f);
    }
}
